home *** CD-ROM | disk | FTP | other *** search
/ Champak 122 / Vol 122.iso / games / sketchbo.swf / scripts / DefineSprite_40 / frame_1 / DoAction.as
Encoding:
Text File  |  2011-01-06  |  1.2 KB  |  57 lines

  1. init = function()
  2. {
  3.    gravity = 4;
  4.    time = getTimer();
  5.    time /= 100;
  6.    rot = random(21) - 10;
  7.    _rotation = random(360);
  8.    floor = _parent.floor;
  9.    bounce = 0.22;
  10.    speedx = random(7) - 3;
  11.    speedystart = 0;
  12.    _init = true;
  13.    gotoAndStop(random(_totalframes) + 1);
  14. };
  15. this.onEnterFrame = function()
  16. {
  17.    if(!_init)
  18.    {
  19.       init();
  20.    }
  21.    timenow = getTimer();
  22.    timenow /= 100;
  23.    speedy = gravity * (timenow - time) + speedystart;
  24.    this._x += speedx / 5;
  25.    this._y += speedy / 5;
  26.    _rotation = _rotation + rot;
  27.    if(this._y > floor)
  28.    {
  29.       this._y = floor;
  30.       speedy *= - bounce;
  31.       time = getTimer();
  32.       time /= 100;
  33.       rot *= -0.5;
  34.       speedystart = speedy;
  35.    }
  36.    if(speedy < 1 && _Y + 2 > floor)
  37.    {
  38.       speedx = 0;
  39.       this.onRotate = function()
  40.       {
  41.          if(_rotation % 360 > 180)
  42.          {
  43.             _rotation = _rotation - _rotation / 3;
  44.          }
  45.          else
  46.          {
  47.             _rotation = _rotation + (- _rotation) / 3;
  48.          }
  49.          if(Math.abs(_rotation) < 2)
  50.          {
  51.             delete this.onRotate;
  52.          }
  53.       };
  54.    }
  55.    onRotate();
  56. };
  57.